home *** CD-ROM | disk | FTP | other *** search
/ Best of Shareware / Best of PC Windows Shareware 1.0 - Wayzata Technology (7111) (1993).iso / mac / DOS / CAD_CAM / A7221V1B / INOUT.H < prev    next >
Text File  |  1992-03-12  |  6KB  |  179 lines

  1. /*
  2.    Module:  inout.h
  3.    Date:    3/9/92
  4.    Version: 1.0b
  5.    Author:  Dave Lutz
  6.    Email:   lutz@psych.rochester.edu
  7.    Copyright: 1992 University of Rochester, Psychology Dept.
  8.  
  9.    Disclaimer:  This software is distributed free of charge.  As such, it
  10.                 comes with ABSOLUTELY NO WARRANTY.  The user of the software
  11.                 assumes ALL RISKS associated with its use.
  12.  
  13.                 Your rights to modify and/or distribute this software are
  14.                 outlined in the file ADI7221.DOC.
  15.  
  16.    Purpose: This module provides the function prototypes for the input/output 
  17.             routines for the ADI converter.  It provides the routines needed 
  18.             by the driver to open input and output files, and read data.  It 
  19.             also provides the output funtion that can be used by the device
  20.             dependant routines to send their output to the file opened by the 
  21.             driver.
  22.  
  23.             A datatype (PLTFILE) is also provided by this module.  This
  24.             datatype is the basic structure used by all of the functions in
  25.             this module.
  26.  
  27.    Functions Provided:
  28.  
  29.             openin
  30.             openout
  31.             closein
  32.             closeout
  33.             getstr
  34.             putarr
  35.  
  36. */
  37.  
  38.  
  39.   /* BUFFSIZE has been set to get the maximum number of 2048 byte clusters
  40.      and still be less than 32767
  41.   */
  42. #define BUFFSIZE 30720
  43. #define PLTFILE struct _pltfile
  44.  
  45. PLTFILE {
  46.    char *buf,     /* start of file buffer */
  47.         *buf_ptr; /* current location in buffer */
  48.    int  fd,       /* file descriptor for the file */
  49.         buf_ctr,  /* number of bytes currently in buffer */
  50.         eof;      /* BOOLEAN flag, only used on input files */
  51. };
  52.  
  53.  
  54.  
  55. /*
  56.    Function: openin
  57.    Purpose:  Allocate the input buffer and open the input file for reading.
  58.  
  59.    Pre: name is a pointer to an ascii string containing the name of the 
  60.         input file.
  61.         pltfpp is a pointer to storage for a pointer to a PLTFILE.
  62.  
  63.    Post:  The input buffer is allocated.
  64.           The input file is opened for reading.
  65.           If the buffer can't be allocated, *pltfpp is set to NULL and
  66.           NOBUFF is returned.
  67.           If the input file can't be opened, *pltfpp is set to NULL and
  68.           BADOPEN is returned.
  69.           Otherwise, TRUE is returned.
  70. */
  71.  
  72. int openin (char *name, PLTFILE **pltfpp);
  73.  
  74.  
  75.  
  76. /*
  77.    Function: openout
  78.    Purpose:  Allocate the output buffer, and open the output file for
  79.              writing.
  80.  
  81.    Pre: name is a pointer to an ascii string containing the name of the
  82.         output file.
  83.         pltfpp is a pointer to storage for a pointer to a PLTFILE.
  84.  
  85.    Post:  The output buffer is allocated.
  86.           The output file is opened for writing.
  87.           If the output buffer can't be allocated, *pltfpp is set to NULL and
  88.           NOBUFF is returned.
  89.           If the output file can't be opened, *pltfpp is set to NULL and
  90.           BADOPEN is returned.
  91.           Otherwise, TRUE is returned.
  92. */
  93.  
  94. int openout (char *name, PLTFILE **pltfpp);
  95.  
  96.  
  97.  
  98. /*
  99.    Function: closein
  100.    Purpose:  Discard the input buffer, close the input file, and deallocate 
  101.              the input buffer.
  102.  
  103.    Pre:  pltfpp is a pointer to a pointer to a PLTFILE.
  104.          If *pltfpp does not point to an open PLTFILE, it is NULL.
  105.  
  106.    Post:  If *pltfpp = NULL, TRUE is returned.
  107.           Otherwise, the contents of the input buffer are discarded, the 
  108.           input file is closed, and the input buffer is deallocated.
  109.           If an error occurs during the above process, FALSE is returned.
  110. */
  111.  
  112. int closein(PLTFILE **pltfpp);
  113.  
  114.  
  115.  
  116. /*
  117.    Function: closeout
  118.    Purpose:  Flush the output buffer, close the output file, and deallocate 
  119.              the output buffer.
  120.  
  121.    Pre:  pltfpp is a pointer to a pointer to a PLTFILE.
  122.          If *pltfpp does not point to an open PLTFILE, it is NULL.
  123.  
  124.    Post:  If *pltfpp = NULL, TRUE is returned.
  125.           Otherwise, the output buffer is flushed, the output file is closed, 
  126.           and the output buffer is deallocated.
  127.           If an error occurs during the above process, FALSE is returned.
  128. */
  129.  
  130. int closeout(PLTFILE **pltfpp);
  131.  
  132.  
  133.  
  134. /*
  135.    Function: getstr
  136.    Purpose:  Read a string from the input buffer, possibly refilling the
  137.              buffer from the input file.  Data is read up to the next
  138.              line feed character.
  139.  
  140.    Pre:  pltfp is a pointer to a PLTFILE that has been opened for reading.
  141.          max is the maximum number of chars to be stored in string.
  142.          string is a pointer to storage for the input string.
  143.          There is enough storage available in string to hold "max"+1 chars.
  144.  
  145.    Post: An attempt is made to read a string from the input buffer and store
  146.          it in "string".
  147.          Reading stops at eof or the first line feed.  The line feed,
  148.          although included in the byte count, is replaced with a NULL.
  149.          If the input buffer is emptied during the process, the input file is 
  150.          read to refill the buffer.
  151.          If "max" chars are read without encountering a line feed, the extra
  152.          chars are discarded.
  153.          The number of bytes read from the input buffer is returned.
  154.          If end_of_file has already been reached, 0 is returned.
  155.          If an error occurs, -1 is returned.
  156. */
  157.  
  158. int getstr (PLTFILE *pltfp, int max, char *string);
  159.  
  160.  
  161.  
  162. /*
  163.    Function: putarr
  164.    Purpose:  Write a char array to the output buffer, possibly causing the 
  165.              buffer to be written to the output file.
  166.  
  167.    Pre: pltfp is a pointer to a PLTFILE that has been opened for writing.
  168.         num is the number of chars to be written to the output buffer.
  169.         chrarr is a pointer to the char array to be written.
  170.  
  171.    Post: An attempt is made to copy num chars from chrarr to the output 
  172.          buffer.
  173.          If the buffer becomes full during the process, an attempt is made
  174.          to write the buffer to the output file.
  175.          If an error occurs, FALSE is returned, otherwise TRUE is returned.
  176. */
  177.  
  178. int putarr (PLTFILE *pltfp, int num, char *chrarr);
  179.